package xhwl.insurance.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import xhwl.insurance.R;
import xhwl.insurance.http.bean.resp.UserGuideListResp;
import xhwl.insurance.ui.UserGudieDetailActivity;

/**
 * Created by Administrator on 2017/8/24.
 * 用户指南页面
 */

public class UserGuideAdapter extends BaseAdapter {
    Context context;
    List<UserGuideListResp> mlist;

    public UserGuideAdapter(Context context, ArrayList<UserGuideListResp> mlist) {
        this.context = context;
        this.mlist = mlist;
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.user_guide_new_item, null);
            holder.title = (TextView) convertView.findViewById(R.id.tv_content);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.title.setText(mlist.get(position).getTitle());
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                
                Intent intent = new Intent(context, UserGudieDetailActivity.class);
                intent.putExtra("title", mlist.get(position).getTitle());
                intent.putExtra("url", mlist.get(position).getUrl());
                context.startActivity(intent);
            }
        });
        return convertView;
    }

    class ViewHolder {
        TextView title;
    }
}
